using UnityEngine;
using System.Collections;

public class MenuManager_exo : MonoBehaviour
{
	public MenuView menuView;
	public SaveManager saveManager;
	public LoadManager loadManager;
	public ScreenshotCapturer screenshotCapturer;

	// Use this for initialization
	void Start ()
	{
		menuView = GameObject.Find("MenuDisplay").GetComponent<MenuView>();
		saveManager = GameObject.Find("SaveLoadManager").GetComponent<SaveManager>();
		loadManager = GameObject.Find("SaveLoadManager").GetComponent<LoadManager>();
		screenshotCapturer = GameObject.Find("SaveLoadManager").GetComponent<ScreenshotCapturer>();
	}
	
	// Update is called once per frame
	void Update ()
	{
	
	}

	public void ReturnToGame()
	{
		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "TextboxUI").SetActive(true);
		menuView.UIMenu.Find(x => x.name == "NameTextboxUI").SetActive(true);
		menuView.UIMenu.Find(x => x.name == "GameUI").SetActive(true);

		if(menuView.menuPanel.activeSelf == true)
			menuView.menuPanel.SetActive(false);

		menuView.menuPanel.SetActive (false);
	}

	public void OpenBacklog()
	{
		screenshotCapturer.toScreenshot();

		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "LogUI").SetActive(true); //I don't know how this one works, but it works. =))
		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);
	}

	public void OpenSaveMenu()
	{
		screenshotCapturer.toScreenshot();

		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "SaveUI").SetActive(true);
		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);

		saveManager.RefreshSaveList();
	}

	public void OpenLoadMenu()
	{
		screenshotCapturer.toScreenshot();

		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "LoadUI").SetActive(true);
		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);

		loadManager.RefreshLoadList();
	}

	public void OpenSettingsMenu()
	{
		screenshotCapturer.toScreenshot();

		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "SettingsUI").SetActive(true);

		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);
	}

	public void OpenInventory()
	{
		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "InventoryPanel").GetComponent<SampleInventoryHandler>().Activate();
		menuView.UIMenu.Find(x => x.name == "InventoryPanel").SetActive(true);
	}

	public void OpenChoiceInventory()
	{
		for(int i = 0; i < menuView.UIMenu.Count; i++)
			menuView.UIMenu[i].SetActive(false);
		menuView.UIMenu.Find(x => x.name == "ChoiceInventoryPanel").GetComponent<ChoiceInventoryHandler>().Activate();
		menuView.UIMenu.Find(x => x.name == "ChoiceInventoryPanel").SetActive(true);
	}

	public void ReturnToMainMenu()
	{
		//return to main menu
		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);
	}

	public void QuitTheGame()
	{
		//quit the game
		if(menuView.menuPanel.activeSelf == false)
			menuView.menuPanel.SetActive(true);
	}
}